//
//  TMThemeObserver.swift
//  ThemeManagement
//
//  Created by fanxiaoxin_1987@126.com on 06/20/2022.
//  Copyright (c) 2022 fanxiaoxin_1987@126.com. All rights reserved.
//

import UIKit

public protocol TMThemeObserverType {
    func doAction()
}
///主题变更观察员
public class TMTargetObserver: TMThemeObserverType {
    weak var observer: AnyObject?
    var actions: [(AnyObject) -> Void] = []
    
    public init(_ observer: AnyObject) {
        self.observer = observer
    }
    ///主题变更时触发
    public func doAction() {
        if let ob = observer {
            actions.forEach({ $0(ob) })
        }
    }
}
///主题变更观察员
public struct TMBlockObserver: TMThemeObserverType {
    let action: () -> Void
    
    public init(_ block: @escaping () -> Void) {
        self.action = block
    }
    ///主题变更时触发
    public func doAction() {
        self.action()
    }
}

